home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Prog
/
M
/
Lex.cpt
/
Lex
/
ObjectC.lxi
< prev
Wrap
Text File
|
1990-06-05
|
2KB
|
138 lines
/*
* C lex
*/
%{
#include <stdlib.h>
#include <console.h>
char *yyval;
%}
digit = [0-9];
letter = [a-zA-Z_];
name = letter(letter|digit)*;
integer = digit digit*;
any = [\0-\377];
white = [ \t\n];
blanks = white*;
%{
main(int argc, char **argv)
{
register int i, len, index;
char buffer[80];
extern char *token();
extern FILE * lexin;
#ifdef THINK_C
console_options.nrows = 10;
cecho2file("clex log", 0, stdout);
cecho2file("clex log", 1, stderr);
/* argc = ccommand(&argv); */
lexin = fopen("test.c", "r");
if(lexin == NULL)
Debugger();
#endif
while (i = yylex()) {
if (i == LEXERR) {
Debugger();
error("LEXERR -- abort");
break;
}
}
putchar('\n');
}
%}
%%
%{
static short blevel = 0, structdef = 0;
short c;
%}
#INCLUDE { /* preprocessor directives */
printf("\nincluding : ");
while((c = lexchar()) != '<' && c != '\"')
;
putchar(c);
while((c = lexchar()) != '>' && c != '\"')
putchar(c);
putchar(c); putchar('\n');
return(LEXSKIP);
}
"#" { /* ignore other preprocessor directives */
comment("\n");
return(LEXSKIP);
}
"{" {
blevel++;
return(LEXSKIP);
}
"}" {
blevel--;
if(blevel == 0)
structdef = 0;
return(LEXSKIP);
}
STRUCT {
if(blevel == 0)
structdef = 1;
return(LEXSKIP);
}
name / blanks ":" {
if(structdef) {
printf("\nclass def:");
structdef = 2;
}
lexecho(stdout);
}
name / blanks "{" {
switch(structdef) {
case 0:
printf("\nunrecognized:");
break;
case 1:
printf("\nordinary struct:");
break;
case 2:
printf("\nsuperclass:");
break;
}
lexecho(stdout);
}
name / blanks "(" {
switch(structdef) {
case 0:
printf("\nmatched function %s:",
blevel>0 ? "use" : "declaration");
break;
case 2:
printf("\nmethod declaration:");
break;
}
lexecho(stdout);
return(1);
}
name {
printf("\nmatched name :\n");
lexecho(stdout);
return(2);
}
integer {
printf("\nmatched integer:\n");
lexecho(stdout);
return(3);
}
"/*" {
comment("*/");
return(LEXSKIP);
}
any {
return(LEXSKIP);
}
%%
error(char *s) {
fprintf(stderr, s);
exit(1);
}
void yyinit() {};